package com.zgt.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.Interceptor;

@SuppressWarnings("serial")
public class AppInterceptor implements Interceptor {
	private Map session;
	public void destroy() {

	}

	public void init() {

	}

	public String intercept(ActionInvocation invocation) throws Exception {
		
		session = invocation.getInvocationContext().getSession(); 
		ActionProxy proxy = invocation.getProxy();
		String method = proxy.getMethod();
		
		if(!method.isEmpty() && !"login".equals(method)){
			if(!session.containsKey("user"))
			return Action.ERROR;
		}
		return invocation.invoke();
	}

}
